package com.fattyCorps.utils.container;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;

// 自动溢出队列
public class AutoPopQueue<T> {
    private CopyOnWriteArrayList<T> list = new CopyOnWriteArrayList<>();
    private int size = 0;

    public AutoPopQueue(int size) {
        this.size = size;
    }

    public List<T> list() {
        List<T> lt = new ArrayList<>();
        for (T obj : list) {
            lt.add(obj);
        }
        return lt;
    }

    public void push(T elem) {
        synchronized (list) {
            if (list.size() >= size) {
                list.remove(0);
            }

            list.add(elem);
        }
    }
}